package com.pretty.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pretty.test.controller.pets.blog.dto.BlogPageDTO;
import com.pretty.test.controller.pets.blog.vo.BlogPageVO;
import com.pretty.test.controller.pets.blog.wrapper.BlogPageWrapper;
import com.pretty.test.entity.PetsBlog;
import com.pretty.test.mapper.PetsBlogMapper;
import com.pretty.test.service.IPetsBlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pretty.test.utils.otherutils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 博客服务实现类
 * @author dujianyu
 * @since 2021-04-08
 */
@Service
public class PetsBlogServiceImpl extends ServiceImpl<PetsBlogMapper, PetsBlog> implements IPetsBlogService {

    @Override
    public List<BlogPageVO> selectBlogPage(BlogPageDTO dto) {
        QueryWrapper queryWrapper  = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        queryWrapper.like(!Func.isBlank(dto.getTitle()),"title",dto.getTitle());
        queryWrapper.like(!Func.isBlank(dto.getKeyword()),"keyword",dto.getKeyword());
        queryWrapper.lt(!Func.isEmpty(dto.getCreateTimeEnd()),"create_time",dto.getCreateTimeEnd());
        queryWrapper.gt(!Func.isEmpty(dto.getCreateTimeStart()),"create_time",dto.getCreateTimeStart());
        queryWrapper.orderByDesc("create_time");
        return BlogPageWrapper.build().listVO(baseMapper.selectList(queryWrapper));
    }
}
